package com.linxianqin.restTemplate.controller;

import com.linxianqin.restTemplate.model.LoginParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author lxq
 * @version 1.0
 * @description: 通过 restTemplate 发送put请求
 * @date 2021/1/14 17:16
 */
@Slf4j
@RestController
public class PutController {
    private RestTemplate restTemplate;
    public PutController(RestTemplate restTemplate){
        this.restTemplate=restTemplate;
    }

    @GetMapping("/put")
    public void put(){
        String url="http://localhost:8080/user/address";
        LoginParam loginParam = new LoginParam();
        loginParam.setUsername("admin");
        loginParam.setPassword("admin123");
        //  执行HTTP请求
        restTemplate.put(url, loginParam, String.class);
    }
}
